/* ******************************************** */
/* * Create Initial Generation                * */
/* * Authors: André Bannwart Perina           * */
/* *          Antonio Canabrava Fraideinberze * */
/* *          Willian Felipe Lopes da Silva   * */
/* ******************************************** */

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>

using namespace std;
/**
 * Generates the individuals with random genes
 */
int main(int argc, char *argv[]) {
    if(argc != 4) {
    	printf("Usage: ./generate <deltaSize> <numberOfIterations> <startIndex>\n");
    	exit(EXIT_FAILURE);
    }

    double deltaSize = atof(argv[1]);
    
    int iterations = atoi(argv[2]);
	int startIndex = atoi(argv[3]);
    
    FILE * pFile;

    char * filename = (char *) malloc(((iterations / 10) + 20) * sizeof(char));

    srand(time(NULL));

    /* Saves into the files the random genes */
    for(int i = startIndex; i < iterations+startIndex; i++) {
    	sprintf(filename, "deltaFiles/file_%d", i);
    	if((pFile = freopen(filename, "w", stdout)) == NULL) {
    	    continue;
    	}
    	
    	cout << deltaSize << "\n";
    	for(int j = 0; j < deltaSize; j++) {
    	    cout << ((rand() % 2) ? 1 : -1) * (rand() % 10) / 10.0 << " ";
    	}
    	
    	cout << "\n";
    	fclose(pFile);
    }

    return 0;
}
